package com.yswl.pri.picture.widgets;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yswl.pri.R;


public class BottomDialog extends Dialog implements View.OnClickListener {
    TextView save;
    TextView copy;
    TextView cancle;
    private Context mContext;
    private View.OnClickListener onSave;
    private View.OnClickListener onCopy;

    public void setOnSave(View.OnClickListener onSave) {
        this.onSave = onSave;
    }

    public void setOnCopy(View.OnClickListener onCopy) {
        this.onCopy = onCopy;
    }

    public BottomDialog(@NonNull Context context) {
        super(context);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.pop_up_bottom_dialog_style);
        window.setBackgroundDrawable(new ColorDrawable());
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.dimAmount = 0.44f;
        window.setAttributes(lp);
        View view = LayoutInflater.from(mContext).inflate(R.layout.bottom_dialog_layout, null);
        save = (TextView) view.findViewById(R.id.btn_save);
        copy = (TextView) view.findViewById(R.id.btn_copy_link);
        cancle = (TextView) view.findViewById(R.id.btn_cancle);
        save.setOnClickListener(this);
        copy.setOnClickListener(this);
        cancle.setOnClickListener(this);
        this.setContentView(view);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_save) {
            if (onSave != null) {
                onSave.onClick(v);
            }
        }
        if (v.getId() == R.id.btn_copy_link) {
            if (onCopy != null) {
                onCopy.onClick(v);
            }
        }
        if (v.getId() == R.id.btn_cancle) {
            this.cancel();
        }
    }
}
